<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>call test</title>
</head>

<body>
    call
    用途：在特定作用域中调用函数，等于设定函数中this的值
    <script>
        let obj={
            x:1,
            sum(num1, num2){//obj.sum
                console.log('sum的this：',this)
                return num1+num2+this.x
            }  
        }
        let obj1={
            x:9
        }
        
        Function.prototype.myCall=function(context,...rest){
            
            context = context||window
            context.func = this //函数实例
            let result
            if(rest){
                result = context.func(...rest)
            }else{
                result = context.func()
            }
            delete context.func 
            return result
        }
        obj.sum(3,4)//8
        obj.sum.myCall(obj1,3,4)//16
    </script>
</body>

</html>